onDataReceived

abstract fun onDataReceived(data: Array<Byte>, port: Int)

Called when new data is received from the specified serial port.

This method is invoked by the serial communication system whenever bytes are read from the serial port that this listener is registered for. The received data is provided as a byte array.

Implementers should process the data byte array according to the expected communication protocol for that serial port. This might involve parsing messages, extracting values, or buffering data for later processing. Care should be taken to handle the data efficiently, as this callback might be invoked frequently depending on the data rate.

Parameters

data

A byte array containing the chunk of data received from the serial port. The array may not be full and its length indicates the number of bytes actually received in this event. This array should not be modified by the listener if it's reused by the caller.

port

The identifier or number of the serial port from which the data was received. This is useful if a single listener instance is registered for events from multiple ports.